#include "GUIManager.h"
#include "GUIObject.h"
#include "Screen.h"
#include "File.h"

GUIObject::GUIObject()
{
	TheGUIManager::Instance()->AddGUIObject(this);
}

GUIObject::~GUIObject()
{
	TheGUIManager::Instance()->RemoveGUIObject(this);
}

void GUIObject::SetTexPath(const std::string& tex)
{
	m_texPath = tex;
}

Vec2f GUIObject::GetDims()
{
	return m_dimensions;
}

void GUIObject::SetDims(const Vec2f& dims)
{
	m_dimensions = dims;
}

const Vec2f& GUIObject::GetPos()
{
	return m_pos;
}

void GUIObject::SetPos(const Vec2f& pos)
{
	m_pos = pos;
}

void GUIObject::CoordConvert()
{
	m_maxPos = m_pos + m_dimensions;

	Vec2i ScreenDims = TheScreen::Instance()->GetScreenSize();

	SDL_GetMouseState(&m_SDLmouseCoord.X, &m_SDLmouseCoord.Y);
	
	/*
	O.GLcoord = 2 / SDLcoord --> gets the correct OGL number per SDL pixel
	^^...^^ * SDLcoord --> times OGL number by amount of pixels

	eg. SDLcoord = 100,100 ScreenDims = 800,600
		OGLcoord.X = 2 \ 800 = 0.0025(per pixel) * 100 = 0.25(actual OGLcoord)
	*/

	// THE X-AXIS
	m_OGLmouseCoord.X = 2 / (float)ScreenDims.X * m_SDLmouseCoord.X;

	// THE Y-AXIS
	//Convert Y axis screen coord from SDL Coords 
	//to OGL Ortho Coords (see diagram at bottom)
	m_SDLmouseCoord.Y = TheScreen::Instance()->GetScreenSize().Y - m_SDLmouseCoord.Y;
	m_OGLmouseCoord.Y = 2 / (float)ScreenDims.Y * m_SDLmouseCoord.Y;
}

/*
  |--->0,0    SDL	  800,0
  |    0,2    OGL	   2,2
  | 	|---------------|
  | 	|				|
  | 	|				|
  | 	|				|
  | 	|				|
  | 	|---------------|
  |-->0,600 		 800,600
	   0,0			   2,2
*/